WEBVTT

00:00.630 --> 00:05.940
In this video you will learn how to create expanding windows so you will see in a minute what I mean

00:05.940 --> 00:06.360
here.

00:06.360 --> 00:14.550
And first of all we import pandas and we are working with the S&amp;P 500 data set and we are only interested

00:14.550 --> 00:16.600
in the last 10 years.

00:16.740 --> 00:20.040
So this is actually nothing new here.

00:20.040 --> 00:25.440
And in the last videos we created rolling windows with a constant window size.

00:25.440 --> 00:32.720
So for example 10 days and by moving forward one day or one timestamp we actually drop the oldest timestamp

00:32.730 --> 00:36.140
and at the most recent time stamp.

00:36.150 --> 00:43.440
So for example we could calculate the rolling mean or the simple moving average for our clothes column

00:43.440 --> 00:50.890
here and our fixed size window is actually here ten days.

00:51.150 --> 00:54.870
So this is actually the rolling average.

00:55.140 --> 01:03.070
And actually in contrast to that with expanding windows our windows increase as we move forward in time.

01:03.120 --> 01:07.540
So at the very first time stem we have only one time for our calculations.

01:07.680 --> 01:11.410
Then at the second timestamp we have two and so on.

01:11.610 --> 01:19.500
And coding wise pandas actually provides us with the surprise expanding method so we can you see the

01:19.500 --> 01:26.610
expanding method on our clothes column and we can calculate actually the expanding mean.

01:26.610 --> 01:34.360
So let's say this here so here we are for the very first time stamp at the thirty first of December

01:34.360 --> 01:36.170
2000 and eight.

01:36.250 --> 01:39.760
And here we have the value of nine hundred three point two five.

01:39.970 --> 01:40.500
And uh.

01:40.540 --> 01:40.790
Yeah.

01:40.800 --> 01:47.920
This is uh simply the very first time stamp here in our close column and then at the second time stamp.

01:47.920 --> 01:51.430
So it's uh the second of January 2009.

01:51.430 --> 01:57.940
If you calculated the expanding mean then pandas simply takes uh the average of those two time stamps

01:58.510 --> 02:04.850
and then at the fifth of January 2009 pandas calculate the mean of um the.

02:04.870 --> 02:13.400
Immediately three proceeding uh timestamps here and so on so let's go down here now and that's actually

02:13.400 --> 02:14.870
for the expanding method.

02:14.880 --> 02:16.100
Uh one parameter.

02:16.100 --> 02:18.100
So let's have a look.

02:18.110 --> 02:20.890
So here we have the min period parameter.

02:21.440 --> 02:26.880
And if we can define the minimum number of observations in a window required to have a value.

02:27.020 --> 02:32.540
So the default setting is 1 but we can also set this for example to 5

02:39.640 --> 02:45.230
so we can see that we get the very first value at the fifth time stamp.

02:45.250 --> 02:47.320
So here we are in total five.

02:47.470 --> 02:50.330
Immediately preceding timestamps actually.

02:50.950 --> 02:54.250
But let's keep here the min periods per meter 2 1

02:58.510 --> 03:02.670
and 2 comparison Bill moving averages and expanding windows.

03:02.770 --> 03:05.860
We can create the two new columns.

03:05.860 --> 03:08.430
So the a simple moving average is 50.

03:08.950 --> 03:11.680
And uh the expanding window.

03:11.680 --> 03:16.970
So let's do this here and let's have a look.

03:16.990 --> 03:19.580
So uh here follow a simple moving averages.

03:19.690 --> 03:23.660
The first the 50 values are obviously any and values.

03:23.660 --> 03:25.280
So no surprise here.

03:25.510 --> 03:31.870
And now we can also visualize those two columns by using the other plot method.

03:32.350 --> 03:39.520
So here we can see in blue the simple moving average 50 and in green the expanding window.

03:39.520 --> 03:47.260
So at each single point in time here we have uh the average price for all of the preceding timestamps.

03:47.350 --> 03:51.490
And we can see here this is a quite stable line.

03:51.490 --> 03:59.250
And the same method with the rolling method you can do more than just the calculating expanding averages.

03:59.680 --> 04:08.020
So for example we can also calculate the expanding minimum stock price for example by changing here

04:08.050 --> 04:09.820
the main method so let's have a look

04:13.730 --> 04:20.690
so this this year the expanding minimum and obviously the total minimum here in the period between 2009

04:20.720 --> 04:25.940
and 2018 is here directly in the year 2009.

04:25.940 --> 04:32.560
And we could also visualize the expanding maximum with the max method

04:40.050 --> 04:43.090
so here we have in green the expanding maximum.

04:43.230 --> 04:53.850
And as our S&amp;P 500 index this year increasing from 2009 to 2018 our expanding maximum see are also increasing.

04:53.850 --> 04:58.110
So these were fewer examples and applications of expanding windows.

04:58.230 --> 05:03.600
And there's actually a lot of more to discover here but for the time being we are finishing with this

05:03.600 --> 05:06.570
video and I hope to see you also in the next one by.
